﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI.WebControls;

namespace BySoft.Web.Utility
{
    public class SystemConfig
    {

        public const int PassErrorTimes = 5;
        /// <summary>
        /// 纪录 几个 历史密码 
        /// </summary>
        public const int RecordHistoryPasswordTimes = 5;
        /// <summary>
        /// 分隔符 用于 历史密码中分隔
        /// </summary>
        public const char Separator = '|';
        public const char Percent = '％';

        public const int CodeLength = 100;
        public const int BtnLength = 40;



        public const bool UseAutoComplete = true;

        public const int BCAccountLength = 4;
        public const int CounterAccountLength = 4;
        public const int VIPAccountLength = 11;

        #region 日期格式
        public const string DBDateTimeFromat_NoMinute = "yyyy-MM-dd hh24:mi";
        public const string DBDateTimeFromat = "yyyy-MM-dd HH:mm:ss";
        /// <summary>
        ///  不包含秒的时间格式
        /// </summary>
        public const string DateTimeFromat_NoMinute = "yyyy-MM-dd HH:mm";
        public const string DateFromat = "yyyy-MM-dd";
        #endregion


        #region 操作
        /// <summary>
        /// 添加
        /// </summary>
        public const string Add = "Add";
        /// <summary>
        /// 编辑
        /// </summary>
        public const string Edit = "Edit";
        /// <summary>
        /// 删除
        /// </summary>
        public const string Delete = "Delete";
        /// <summary>
        /// 查看
        /// </summary>
        public const string View = "View";
        #endregion

        #region 常量Id
        /// <summary>
        /// BC角色的Id
        /// </summary>
        public const string BC_RoleID = "a66cc91e-3e8f-4dce-afed-a1bff3cb17f4";
        /// <summary>
        /// 首页Id
        /// </summary>
        public const string FirstPageId = "0100";
        #endregion

        #region 查询结果最大长度
        /// <summary>
        /// Web
        /// </summary>
        public const int MaxRowNumber = 1000;
        /// <summary>
        /// PDA
        /// </summary>
        public const int PDAMaxRowNumber = 50;
        #endregion

        #region 显示行数
        public const int PageSize = 20;
        #endregion


        public static string GetHistoryPassWord(string oldHistoryPassword, string oldPassword)
        {
            if (String.IsNullOrEmpty(oldHistoryPassword))
                return oldPassword;

            string[] historyPasswords = oldHistoryPassword.Split(SystemConfig.Separator);

            if (historyPasswords.Length < RecordHistoryPasswordTimes)
            {
                return oldHistoryPassword + SystemConfig.Separator + oldPassword;
            }
            else
            {
                return oldHistoryPassword.Substring(historyPasswords[0].Length + 1) + SystemConfig.Separator + oldPassword;
            }
        }
        public static bool CheckIsInHistoryPassword(string historyPassword, string newPassword)
        {
            //验证密码是否重复
            string[] historyPasswords = historyPassword.Split(SystemConfig.Separator);
            foreach (string temp in historyPasswords)
            {
                if (newPassword == temp)
                {
                    //break;
                    return true;
                }
            }
            return false;
        }

        /// <summary>
        /// 用于orcal数据库中 to_date
        /// 返回 如：to_date('2007-10-26','yyyy-mm-dd hh24:mi:ss')
        /// </summary>
        /// <param name="date">需要格式化的Date</param>
        /// <returns>to_date('2007-10-26','yyyy-mm-dd hh24:mi:ss')</returns>
        public static string FromatDateToDB(string date)
        {
            return "to_date('" + date + "','" + DBDateTimeFromat + "')";
        }
    }
}
